﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PalBattleEmulator.Command;
using PalBattleEmulator.Graphic;

namespace PalBattleEmulator
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            //ContextModules.GameClockManager.Launch();
            ContextModules.GameClockManager.BattleStart();
        }

        private void stopButton_Click(object sender, RoutedEventArgs e)
        {
            ContextModules.GameClockManager.Stop();
        }

        private void Window_Initialized(object sender, EventArgs e)
        {
            //Dispatcher
            ContextModules.MainDispatcher = this.Dispatcher;
            
            //初始化各模块
            ContextModules.InitializeModules();

            //初始化数据
            GameContext.Initialize();

            //生成绘图控件
            GameGraphicManager graphic = new GameGraphicManager();
            battleViewBorder.Child = graphic;
            ContextModules.GraphicControl = graphic;
            ContextModules.GameClockManager.GraphicControl = graphic;

            //启动主循环
            ContextModules.GameClockManager.Launch();
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            KeyboardInputCommand command = new KeyboardInputCommand(CommandTypes.INPUT_KEYBOARD_DOWN);
            command.KeyEvent = e;
            ContextModules.GameClockManager.OnCommand(command);
        }
    }
}
